package p;

public class Account {
    private String num;
    private int balance;
    private Integer aaaaaaaa = new Integer(5);

    public Account() {
    }

    public Account(String num, int balance) {
        this.num = num;
        this.balance = balance;
    }

    public String getNum() {
        return num;
    }

    public void setNum(String num) {
        this.num = num;
    }

    public int getBalance() {
        return balance;
    }

    public void setBalance(int balance) {
        this.balance = balance;
    }
    public  void withdraw (int money) {//取钱
        synchronized (aaaaaaaa){
            int before = this.getBalance();//获取余额
            int after = before - money;//取出后余额应为
            try {
                Thread.sleep(500);//假设网络延迟0.5秒
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            this.setBalance(after);//0.5秒后更新余额
            System.out.println(Thread.currentThread().getName()+"已取出"+money+"目前余额为："+this.getBalance());
        }
    }
}
